#!/usr/bin/python3
# -*- coding:UTF-8 -*-
'''Module DocString'''

__author__ = 'Wang Zhe'

from socket import *
from time import ctime
import sys
reload(sys)
sys.setdefaultencoding('utf-8')


def tcp():
    """Function DocString"""
    port = 8081
    host = ''
    bufsize = 1024
    addr = (host, port)
    s = socket(AF_INET, SOCK_STREAM)
    s.bind(addr)
    s.listen(5)
    while True:
        print('waiting for connection')
        tcpClientSock, addr = s.accept()
        print('connect from ', addr)
        while True:
            data = tcpClientSock.recv(bufsize)
            if not data:
                break
            string = 'Hi,you send me :[%s] %s' % (
                ctime(), data)
            tcpClientSock.send(string)
            print([ctime()], ':', data.decode("utf-8").encode("GBK"))
            print(data.decode("utf-8"))
            print(data)
            print(data.decode("utf-8").encode("GBK"))
        tcpClientSock.close()
    s.close()


def main():
    '''Func DocString'''
    tcp()
    pass


if __name__ == '__main__':
    main()
